As we mentioned earlier, the bslib package provides a modern UI toolkit for Shiny, R Markdown, and Quarto based on Bootstrap. It provides,
Custom theming of Shiny apps and R Markdown documents
Switch between different versions of Bootstrap
Modern UI components like cards, value boxes, sidebars, and more.
We will now take a look at the first two of these features.
Bootswatch
Due to the ubiquity of Bootstrap a large amount of community effort has gone into developing custom themes - a large free collection of these are available at bootswatch.com/.
bs_theme()
Provides a high level interface to adjusting the theme for an entire Shiny app,
Change bootstrap version via version argument
Pick a bootswatch theme via bootswatch argument
Adjust basic color palette (bg, fg, primary, secondary, etc.)
The object returned by bs_theme() can be passed to the theme argument of fluidPage() and similar page UI elements.
thematic
Simplified theming of ggplot2, lattice, and {base} R graphics. In addition to providing a centralized approach to styling R graphics, thematic also enables automatic styling of R plots in Shiny, R Markdown, and RStudio.
In the case of our flexdashboard (or other shiny app), all we need to do is to include a call to thematic_shiny() before the app is loaded.
Using the value "auto" will attempt to resolve the bg, fg, accent, or font values at plot time.
Using code provided in exercises/ex06.R (which is the same as Demo 9’s) experiment with bslib’s themer tool to explore different themes .
Try changing the main theme as well as the foreground and background colors
Try changing one or more of the accent colors
Try the fonts being used (e.g. Prompt, roboto, Oswald, Fira Sans) and changing the base font size
10:00
Deploying Shiny apps
Your turn - Exercise 07
Go to shinyapps.io and sign up for an account if you don’t have one already.
You can create a new account via email & a password
or via o-auth through Google or GitHub.
If asked to pick a plan, use the Free option (more than sufficient for our needs here)
03:00
Organizing your app
For deployment generally apps will be organized as a single folder that contains all the necessary components (R script, data files, other static content).
Pay attention to the nature of any paths used in your code
Absolute paths are almost certainly going to break
Relative paths should be to the root of the app folder
Static files (e.g. css, js, etc.) generally are placed in the www/ subfolder
Your script does not need to be named app.R or ui.R/server.R
Check / think about package dependencies
Your turn - Exercise 08
Now we will publish our app to shinyapps.io (you will need to have completed Exercise 7)
Package up ex08.R as an app in exercises/ex08app (you will need to create this folder)
Make sure to copy the data (weather.csv) into this folder
Adjust any paths if necessary
Open the script file in exercises/ex08app and click the Publish Document button in the upper right of the pane (look for the icon)
You should be presented with the “Publish to server”, click on the Add New Account link in the upper right
Select shinyapps.io and follow the instructions to connect
When retrieving your token for shinyapps.ip you may need to click Dashboard first and then your name (both in the upper right)
Your turn - Exercise 08 (cont.)
Once authenticated you should be back at the “Publish to server” dialog, use this to select which files to include (select your script and data file)
Your Shiny app should now be deploying and should open on shinyapps.io once live - check to see if everything works, if not go back and check Steps 1 and 3.
10:00
Demo 12 - shinylive
One of the really exciting developments in the last couple of years is the ability to run R (and Python) inside a web browser using webasm. shinylive is a package that lets you bundle your shiny app as a static website that can be hosted any number of places.
The Shiny User Showcase is comprised of contributions from the Shiny app developer community. The apps are categorized into application areas and presented with a brief description, tags, and for many, the source code. Note that many of these apps are winners and honorable mentions of our annual Shiny contest!
The R package DT provides an R interface to the JavaScript library DataTables. R data objects (matrices or data frames) can be displayed as tables on HTML pages, and DataTables provides filtering, pagination, sorting, and many other features in the tables.
The goal of the pool package is to abstract away the logic of connection management and the performance cost of fetching a new connection from a remote database. These concerns are especially prominent in interactive contexts, like Shiny apps (which connect to a remote database) or even at the R console.
The goals of the Shiny Developer Series are to showcase the innovative applications and packages in the ever-growing Shiny ecosystem, as well as the brilliant developers behind them! The series is composed of these components: